/*
 * Created on 2005-9-21
 *
 * 
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.dcivision.form.web;

import java.util.Calendar;

import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.TextUtility;
import com.dcivision.framework.Utility;
import com.dcivision.framework.web.AbstractSearchForm;

/**
 * @author vera
 *
 * 
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ListFormAuditTrailForm  extends AbstractSearchForm {

  public ListFormAuditTrailForm() {
    super();
    this.setSortAttribute("CREATE_DATE");
    this.setSortOrder("DESC");
  }

   /** Holds value of property updateDateFrom.  */
  private String accessDateFrom;

  /** Holds value of property updateDateTo.  */
  private String accessDateTo;

  /** Holds value of property periodType.   */
  private String periodType = "month";
  
  private String userRecordID = "";
  
  /** Getter for property updateDateFrom.
   * @return Value of property updateDateFrom.
   */
  public String getAccessDateFrom() {
    Calendar cal = Calendar.getInstance();
    if(Utility.isEmpty(periodType)){
      return accessDateFrom;
    }else if("week".equals(periodType)){
      cal.add(Calendar.DATE,1-cal.get(Calendar.DAY_OF_WEEK));
    }else if("month".equals(periodType)){
      cal.set(Calendar.DATE,1);
    }else if("full".equals(periodType)){
      return null;
    }
    cal.set(Calendar.AM_PM, Calendar.AM);
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return TextUtility.formatDate(cal.getTime(), SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT));
  }

  /** Setter for property updateDateFrom.
   * @param updateDateFrom New value of property updateDateFrom.
   */
  public void setAccessDateFrom(String accessDateFrom) {
    this.accessDateFrom = accessDateFrom;
  }

  /** Getter for property updateDateTo.
   * @return Value of property updateDateTo.
   */
  public String getAccessDateTo() {
    Calendar cal = Calendar.getInstance();
    if(Utility.isEmpty(periodType)){
      return accessDateTo;
    }else if("week".equals(periodType)){
      cal.add(Calendar.DATE,7-cal.get(Calendar.DAY_OF_WEEK));
    }else if("month".equals(periodType)){
      cal.add(Calendar.MONTH,1);
      cal.set(Calendar.DATE,0);
    }else if("full".equals(periodType)){
      return null;
    }
    cal.set(Calendar.AM_PM, Calendar.PM);
    cal.set(Calendar.HOUR, 11);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 59);
    return TextUtility.formatDate(cal.getTime(), SystemParameterFactory.getSystemParameter(SystemParameterConstant.DB_DATETIME_FORMAT));
  }

  /** Setter for property updateDateTo.
   * @param updateDateTo New value of property updateDateTo.
   */
  public void setAccessDateTo(String accessDateTo) {
    this.accessDateTo = accessDateTo;
  }
  
  /** Getter for property periodType.
   * @return Value of property periodType.
   */
  public String getPeriodType() {
    return this.periodType;
  }

  /** Setter for property periodType.
   * @param periodType New value of property periodType.
   */
  public void setPeriodType(String periodType){
    this.periodType = periodType;
  }
  
  public String getUserRecordID(){
    return(this.userRecordID);
  }

  public void setUserRecordID(String userRecordID){
    this.userRecordID=userRecordID;
  }
}
